package com.mailsending.controller;

import com.mailsending.entity.EmailEntity;
import com.mailsending.service.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

@RestController
public class EmailSendingController {

    @Autowired
    private MailService mailService;

    /**
     * 发送邮件的主界面
     */
    @GetMapping("/")
    public ModelAndView index() {
        ModelAndView mv = new ModelAndView("sendMail");//打开发送邮件的页面
        mv.addObject("sender", mailService.getMailSendFrom());//邮件发信人
        return mv;
    }

    @PostMapping("/send_mail")
    public EmailEntity sendmail(EmailEntity entity, MultipartFile[] multipartFiles){
        System.out.println(multipartFiles);
        entity.setMultipartFiles(multipartFiles);
        System.out.println("发件人："+entity.getSender());
        return mailService.sendMail(entity);
    }
}
